package dp;

public class P397 {
    public int integerReplacement(int n) {
        byte[] dp = new byte[n + 1];
        dp[1] = 0;
        dp[2] = 1;
        for (int i = 3; i <= n; i++) {
            if (i % 2 == 0) {//偶数
                dp[i] = (byte) (dp[i / 2] + 1);
            } else { //奇数
                dp[i] = (byte) Math.min(dp[i - 1] + 1, dp[(i + 1) / 2] + 2);
            }
        }
        return dp[n];
    }

    public static void main(String[] args) {
        int count = new P397().integerReplacement(200000000);
        System.out.println(count);
    }
}
